/*
 * table_CppMacroDefInfo.c
 *
 *  Created on: 2012/03/30
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"

/* KIND_MACRODEFINFO	*/
typedef struct _MACRODEFINFO
{
	AST		astMacroName;	/* 2 */
	U2		usKind;		/* 3 */
	S2		sParamCnt;	/* 4 */
	AST		astExtStart;		/* 5 */
	AST		astExtEnd;		/* 6 */
	AST		astDirectiveInfo;	/* 7 */
	UCHAR		bDefined;		/* 8 */
	UCHAR		bVariableArg;
}MACRODEFINFO, *PMACRODEFINFO;



#define TableSize  (sizeof(MACRODEFINFO))
#define TableType  PMACRODEFINFO
#define stTable stMacroInfoManager.memoryBlocks
#define maxTable stMacroInfoManager.maxRecordNum
#define  maxNumPerBlk  (stMacroInfoManager.astMaxNum_Block)

/* get the object */
static TABLEMANAGER stMacroInfoManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stMacroInfoManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stMacroInfoManager,  resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stMacroInfoManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stMacroInfoManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stMacroInfoManager, astReqArg, resetListener );
}
static AST getMaxLineNum (VOID)
{
	return maxTable;
}
//ACCESS_U2_FIELD  macroKind;
static U2 getMacroKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usKind;
}
static U2 setMacroKind( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usKind = value;
}
//ACCESS_S2_FIELD  paramNum;
static S2 getParamNum( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->sParamCnt;
}
static S2 setParamNum( AST index, S2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->sParamCnt = value;
}
//ACCESS_BOOL_FIELD bValid;
static BOOL getValidFlag( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bDefined;
}
static BOOL setValidFlag( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bDefined = value;
}
//ACCESS_BOOL_FIELD bVariableParam;
static BOOL getVariableParamFlag( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bVariableArg;
}
static BOOL setVariableParamFlag( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bVariableArg = value;
}
//ACCESS_IDX_FIELD  startReplaceEle;
static AST getStartEle( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astExtStart;
}
static AST setStartEle( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astExtStart = idx;
}
//ACCESS_IDX_FIELD  endReplaceEle;
static AST getLastEle( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astExtEnd;
}
static AST setLastEle( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astExtEnd = idx;
}
//ACCESS_IDX_FIELD  directiveInfo;
static AST getDirectInfo( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDirectiveInfo;
}
static AST setDirectInfo( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDirectiveInfo = idx;
}
//ACCESS_STR_FIELD  macroName;
static CHAR* getMacroName( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return "";
	}
	return stCoreLabelStrAccess.getStr( pTbl->astMacroName );
}
static AST setMacroName( AST index, PSZ str )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMacroName = stCoreLabelStrAccess.addStr( str );
}

const MACRODEFINFOACCESS stCoreMacroDefInfoAccess = {
//		BOOL (*clear)( VOID );
		ClearTable,
//		BOOL (*reset)( VOID );
		ResetTable,
//		BOOL (*alloc)( AST );
		AllocTable,
//		AST  (*getMax)( VOID );
		getMaxLineNum,
//		ACCESS_U2_FIELD  macroKind;
		{
				getMacroKind,
				setMacroKind
		},
//		ACCESS_S2_FIELD  paramNum;
		{
				getParamNum,
				setParamNum
		},
//		ACCESS_BOOL_FIELD bValid;
		{
				getValidFlag,
				setValidFlag
		},
//		ACCESS_BOOL_FIELD bVariableParam;
		{
				getVariableParamFlag,
				setVariableParamFlag
		},
//		ACCESS_IDX_FIELD  startReplaceEle;
		{
				getStartEle,
				setStartEle
		},
//		ACCESS_IDX_FIELD  endReplaceEle;
		{
				getLastEle,
				setLastEle
		},
//		ACCESS_IDX_FIELD  directiveInfo;
		{
				getDirectInfo,
				setDirectInfo
		},
//		ACCESS_STR_FIELD  macroName;
		{
				getMacroName,
				setMacroName
		}
};
/* end of file */
